<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script setup>
// 应用根组件
import { onMounted } from 'vue'
import '@/styles/mobile.css'
import '@/styles/desktop.css'

// 检测设备类型并添加类名
onMounted(() => {
  const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
  const isSmallScreen = window.innerWidth <= 768
  
  // 初始化设备类型
  const updateDeviceClass = () => {
    const width = window.innerWidth
    document.body.classList.remove('mobile-device', 'tablet-device', 'desktop-device')
    
    if (isMobile || width <= 768) {
      document.body.classList.add('mobile-device')
    } else if (width <= 1024) {
      document.body.classList.add('tablet-device')
    } else {
      document.body.classList.add('desktop-device')
    }
  }
  
  // 初始调用
  updateDeviceClass()
  
  // 监听屏幕尺寸变化
  const handleResize = () => {
    updateDeviceClass()
  }
  
  window.addEventListener('resize', handleResize)
  
  // 组件卸载时清理事件监听
  return () => {
    window.removeEventListener('resize', handleResize)
  }
})
</script>

<style>
#app {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  /* 防止iOS自动调整字体大小 */
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  background-color: #f5f7fa;
  /* 防止橡皮筋效果 */
  overscroll-behavior: none;
  /* 优化移动端滚动 */
  -webkit-overflow-scrolling: touch;
}

/* 移动端全局优化 */
body.mobile-device {
  font-size: 14px;
  line-height: 1.5;
}

/* 防止移动端点击高亮 */
body.mobile-device * {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* 允许输入框和可编辑内容被选择 */
body.mobile-device input,
body.mobile-device textarea,
body.mobile-device [contenteditable="true"] {
  -webkit-user-select: auto;
  user-select: auto;
}

/* 优化移动端滚动条 */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* 移动端安全区域适配 */
@supports (padding: max(0px)) {
  body.mobile-device {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
}

/* 桌面端样式保护 */
@media (min-width: 769px) {
  .el-container {
    flex-direction: column !important;
  }
  
  .el-header {
    height: 60px !important;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  }
  
  .el-main {
    padding: 20px !important;
  }
  
  .el-aside {
    width: 200px !important;
    height: auto !important;
  }
}

/* Element Plus 移动端优化 */
@media (max-width: 768px) {
  .el-container {
    flex-direction: column !important;
  }
  
  .el-header {
    height: auto !important;
    min-height: 50px !important;
  }
  
  .el-main {
    padding: 12px !important;
  }
  
  .el-aside {
    width: 100% !important;
    height: auto !important;
  }
  
  /* 表格响应式 */
  .el-table--fit {
    overflow: visible !important;
  }
  
  .el-table__fixed,
  .el-table__fixed-right {
    display: none !important;
  }
  
  /* 分页器适配 */
  .el-pagination {
    text-align: center !important;
  }
  
  .el-pagination__total,
  .el-pagination__sizes {
    display: none !important;
  }
}

/* 超小屏幕优化 */
@media (max-width: 480px) {
  body.mobile-device {
    font-size: 13px;
  }
  
  .el-main {
    padding: 8px !important;
  }
}
</style>
